<?php
namespace App\Http\Controllers\AdminApi;
use App\Repository\BaseController\ApiController;
use App\Repository\Sys\JsonRespose;
use App\Repository\Sys\Str;
//留言管理
class MessageController extends ApiController{
	//在线留言-列表
    public function getMessageList(){
        $page = \Request::get('page', 1);
        $limit = \Request::get('page_num', 10);
        $title = \Request::get('title');
        $offset = ($page - 1) * $limit;
        //拼接sql
        $where = "1=1";
        $parameters = array(
            'limit' => $limit,
            'offset' => $offset
        );
        if ($title) {
            $where .= " AND  d.title LIKE :title ";
            $parameters['title'] = $title;
        }
        $sql = "select * from message as d  WHERE {$where} ORDER BY d.id DESC limit  :offset,:limit;";
        //执行sql
        $res = \DB::select($sql, $parameters);
        unset($parameters['limit'], $parameters['offset']);
        $count = \DB::select("select count(*) as c from message as d WHERE {$where}", $parameters)[0]->c;
        $data=[];
        foreach ($res as $v){
        	$v->created_at = Str::dateFormat('Y-m-d', $v->created_at);
        	$data[] = $v;
        }
        return JsonRespose::success([
            'count' => $count,
            'limit' => $limit,
            'page' => $page,
            'res' => $data
        ]);
    }
}
